package com.ldd.malphite.aspcet;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class QueryAspect {

    private static String QUERY_COUNT = "QUERY_COUNT";

    @Autowired
    private RedisTemplate  redisTemplate;

    @Before("execution(public * com.ldd.malphite.controller.*.*(..))")
    public void queryCount(JoinPoint joinPoint){
        String name = joinPoint.getSignature().getName();
        redisTemplate.opsForValue().increment(QUERY_COUNT+":"+name);
    }
}
